
<template>
    <div style="width: 100%">
        <div v-if="param != '年龄'">
            <div class="sqlmulpagetop">
                <div style="width: 100%; height: 100%">
                    <div style="width: 430px; float: left">
                        <el-input v-model.trim="txtSqlListQuery" placeholder="请输入查询条件" style="width: 430px" ref="refsearch" clearable></el-input>
                    </div>
                    <div style="width: 430px; float: right" v-if="this.prono == 'LIS848' || this.prono == 'LIS117'">
                        <el-radio-group v-model="radioType">
                            <el-radio :label="1">满 足</el-radio>
                            <el-radio :label="0">除 外</el-radio>
                        </el-radio-group>
                        <el-radio-group v-if="param == '其他项目'" v-model="itemgermflag" @change="changeItemgermflag">
                            <el-radio :label="1">阴性结果</el-radio>
                            <el-radio :label="4">涂片结果</el-radio>
                        </el-radio-group>
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <el-button @click="SqlDialogVisibleSaveLIS848" style="margin-left: 1px" icon="el-icon-document">确 定</el-button>
                        &nbsp;&nbsp;&nbsp;
                        <el-button @click="SqlDialogVisibleCloseLIS848" type="primary" style="margin-left: 1px" icon="el-icon-close">取 消</el-button>
                    </div>
                    <div class="dialog-btn" v-else-if="this.prono == 'BAC113'">
                        <el-button @click="saveDataDialog" style="margin-left: 1px" icon="el-icon-document">确 定</el-button>
                        <el-button @click="closeDataDialog" type="primary" icon="el-icon-close">取 消</el-button>
                    </div>
                    <div style="width: 430px; float: right" v-else>
                        <el-button @click="SqlTabledatafirst()" style="margin-left: 1px">首位</el-button>
                        <el-button @click="SqlTabledataup()" style="margin-left: 1px">上移</el-button>
                        <el-button @click="SqlTabledatadown()" style="margin-left: 1px">下移</el-button>
                        <el-button @click="SqlTabledatalast()" style="margin-left: 1px">末位</el-button>
                        &nbsp;&nbsp;
                        <el-button v-if="this.prono == 'LIS653'" @click="SqlDialogVisibleEliminate" style="margin-left: 1px">剔除</el-button>
                        <el-button @click="SqlDialogVisibleSave" style="margin-left: 1px">确 定</el-button>
                        <el-button @click="SqlDialogVisibleClose" type="primary" style="margin-left: 1px">取 消</el-button>
                         <div style="width: 150px;float: right">
                        <el-input v-model.trim="txtrightQuery" placeholder="请输入查询条件" style="width: 150px" ref="rightrefsearch" clearable ></el-input></div>
                    </div>
                </div>
            </div>
            <div class="sqlmulpagecenter">
                <div style="width: 430px">
                    <!-- <vxe-table :data.sync="list" @cell-dblclick="SQLSelectEvent" height="auto" highlight-current-row highlight-hover-row highlight-hover-column resizable show-header-overflow="tooltip" border fit show-overflow="tooltip" header-align="center" size="mini" stripe ref="PopxTableLeft">
                        <vxe-table-column type="index" title="NO." align="center" width="50px"></vxe-table-column>
                        <vxe-table-column v-for="item in tableColumn.filter(one=>!one.hasOwnProperty('type'))" :key="item.field" :field="item.field" :title="item.title" :width="item.width"></vxe-table-column>
                    </vxe-table> -->
                    <vxe-grid v-if="prono == 'LIS118'" :columns="depttableColumn" height="auto" header-align="center" :edit-config="{ trigger: 'click', mode: 'cell', showStatus: true, showIcon: false }" border :optimization="{scrollY:{gt:1000}}" @cell-dblclick="SQLSelectEvent" :data.sync="list" show-overflow :select-config="selectConfig" highlight-current-row highlight-hover-row ref="PopxTableLeft" resizable size="mini" stripe :key="leftkey"> </vxe-grid>
                     <vxe-grid v-else :columns="tableColumn" height="auto" header-align="center" :edit-config="{ trigger: 'click', mode: 'cell', showStatus: true, showIcon: false }" border :optimization="{scrollY:{gt:1000}}" @cell-dblclick="SQLSelectEvent" :data.sync="list" show-overflow :select-config="selectConfig" highlight-current-row highlight-hover-row ref="PopxTableLeft" resizable size="mini" stripe :key="leftkey"> </vxe-grid>
                </div>
                <div class="table-deal-btn">
                    <div>
                        <el-button class="btn-other" @click="SQLSelectEvent">
                            <i class="el-icon-right"></i>
                        </el-button>
                    </div>
                    <div>
                        <el-button class="btn-other" @click="SQLNoSelectEvent">
                            <i class="el-icon-back"></i>
                        </el-button>
                    </div>
                    <div>
                        <el-button class="btn-other" @click="SqlAllSelect">
                            <i class="el-icon-d-arrow-right"></i>
                        </el-button>
                    </div>
                    <div>
                        <el-button class="btn-other" @click="SqlAllNoSelect">
                            <i class="el-icon-d-arrow-left"></i>
                        </el-button>
                    </div>
                    <div>
                        <el-button class="btn-exchange" @click="SqlChkExchange">
                            <i class="el-icon-sort"></i>
                        </el-button>
                    </div>
                </div>
                <div style="width: 430px">
                    <!-- <vxe-grid :columns="tableColumn" height="auto" header-align="center" :edit-config="{ trigger: 'click', mode: 'cell', showStatus: true, showIcon: false }" border @cell-dblclick="SQLNoSelectEvent" @current-change="SqlCurrSelectEvent" :data.sync="RightSqlListOptions" show-overflow :select-config="selectConfig" highlight-current-row highlight-hover-row ref="PopxTableRight" resizable size="mini" stripe :key="rightkey"> </vxe-grid> -->
                     <vxe-grid v-if="prono == 'LIS118'" :columns="depttableColumn" height="auto" header-align="center" :edit-config="{ trigger: 'click', mode: 'cell', showStatus: true, showIcon: false }" border @cell-dblclick="SQLNoSelectEvent" @current-change="SqlCurrSelectEvent" :data.sync="rightlist" show-overflow :select-config="selectConfig" highlight-current-row highlight-hover-row ref="PopxTableRight" resizable size="mini" stripe :key="rightkey"> </vxe-grid>
                    <vxe-grid v-else :columns="tableColumn" height="auto" header-align="center" :edit-config="{ trigger: 'click', mode: 'cell', showStatus: true, showIcon: false }" border @cell-dblclick="SQLNoSelectEvent" @current-change="SqlCurrSelectEvent" :data.sync="rightlist" show-overflow :select-config="selectConfig" highlight-current-row highlight-hover-row ref="PopxTableRight" resizable size="mini" stripe :key="rightkey"> </vxe-grid>
                </div>
            </div>
            <div v-show="false">{{ leftOption }}</div>
        </div>
        <div v-else-if="param == '年龄'">
            <div class="sqlmulpagetop">
                <div class="dialog-btn">
                    <el-button @click="addAge">新增</el-button>
                    <el-button @click="deleteAge">删除</el-button>
                    <el-button @click="saveAgeDialog(1)" icon="el-icon-document">确 定</el-button>
                    <el-button @click="saveAgeDialog(2)" type="primary" icon="el-icon-close">取 消</el-button>
                </div>
            </div>
            <div style="height: 200px">
                <vxe-table ref="ageTable" :data.sync="ageList" :keyboard-config="keyConfig" :select-config="{ reserve: true }" :sort-config="{ trigger: 'cell' }" border height="auto" class="mytablestyle" highlight-current-row show-overflow size="mini" show-header-overflow resizable header-align="center" :edit-config="{ trigger: 'click', mode: 'cell', showStatus: true, showIcon: false }" :edit-rules="ageValidRules" :edit-changing="ageEditchange">
                    <vxe-table-column key="ageyear1" field="ageyear1" title="起始年龄(岁)>=" :edit-render="{ name: 'input', autoselect: true }" width="150"></vxe-table-column>
                    <vxe-table-column key="ageyear2" field="ageyear2" title="结束年龄(岁)<=" :edit-render="{ name: 'input', autoselect: true }" width="150"></vxe-table-column>
                </vxe-table>
            </div>
        </div>
        <!-- <div v-else-if="param == '菌落计数'">
			<div style="width: 250px;padding: 5px 0 10px;">
				<div style="display: flex;justify-content: space-between;margin-bottom: 5px;">
					<div>取值：</div>
					<div>
						<el-button @click="saveBactcountDialog(1)" style="margin-left: 1px">确 定</el-button>
						<el-button @click="saveBactcountDialog(2)" type="primary" style="margin-left: 1px">取 消</el-button>
					</div>
				</div>
				<el-radio-group v-model="bactcountVlaue">
					<el-radio label="">不设置</el-radio>
					<el-radio label="为空">为空</el-radio>
					<el-radio label="不为空">不为空</el-radio>
				</el-radio-group>
			</div>
		</div> -->
    </div>
</template>

<script type="text/javascript">
import XEUtils from "xe-utils";
export default {
    props: {
        //第一种传递方式，直接传递左边和右边的option
        leftOption: { type: Array },
        rightOption: { type: Array },
        name: { type: String },
        prono: { type: String, default: "" },
        LIS848radio: { type: Number, default: 1 },
        datatype: { type: String, default: "" },
        rightValue: { type: String, default: "" },
        rptunitid: [Number, String],
        //第二种传递方式，传递所有的option和右边字符
        // RightOptionAsStr: { type: String, default: 'RDATA' },
        // AllOption: { type: Array },
        param: { type: String },
        age: { type: Array },
        // bactcount: { type: String},
    },
    data() {
        return {
            txtSqlListQuery: "",
            SqlDialogVisible: true,
            tableColumn: [
                { type: "index", title: "NO.", width: 50, align: "center" },
                { field: "data", title: "代码", width: 80 },
                { field: "display", title: "名称", width: 150 },
                { field: "inputcode", title: "输入码", width: 100 },
            ],
            depttableColumn: [
                { type: "index", title: "NO.", width: 40, align: "center" },
                { field: "data", title: "代码", width: 55 },
                { field: "display", title: "名称", width: 125 },
                { field: "inputcode", title: "输入码", width: 90 },
                 { field: "subjectname", title: "专业类别", width: 100 },
            ],
            selectConfig: { tigger: "row" },
            sqlcurrRowIndex: 0,
            LeftSqlListOptions: [],
            RightSqlListOptions: [],
            leftkey: 0,
            rightkey: 0,
            isFirstLoad: true,
            //AllDataOption:[],
            //RightOptionStr:""
            keyConfig: {
                isDel: true,
                isTab: true,
                isEdit: true,
                isArrow: true,
            },
            ageValidRules: {
                ageyear1: [{ required: true, message: "必须填写起始年龄" }],
                ageyear2: [{ required: true, message: "必须填写结束年龄" }],
            },
            ageList: [],
            radioType: 1,
            itemgermflag: "1",
            AllOption: [], //全部选项结果
            // bactcountVlaue: "",
            txtrightQuery:"",
        };
    },
    computed: {
        list() {
            if (this.LeftSqlListOptions.hasOwnProperty("errcode")) return [];
            let filterName = this.txtSqlListQuery;
            if (filterName) {
                let rest = this.LeftSqlListOptions.filter((item) => {
                    if (item.hasOwnProperty("inputcode")) {
                        if(this.prono == "LIS118"){
                            return (item.data ? item.data.toString().toUpperCase().indexOf(filterName.toString().toUpperCase()) > -1 : false) || (item.display ? item.display.indexOf(filterName) > -1 : false) || (item.inputcode ? item.inputcode.toString().toUpperCase().indexOf(filterName.toString().toUpperCase()) > -1 : false)|| (item.subjectname ? item.subjectname.indexOf(filterName) > -1 : false);
                        }
                        else{
                            return (item.data ? item.data.toString().toUpperCase().indexOf(filterName.toString().toUpperCase()) > -1 : false) || (item.display ? item.display.indexOf(filterName) > -1 : false) || (item.inputcode ? item.inputcode.toString().toUpperCase().indexOf(filterName.toString().toUpperCase()) > -1 : false);
                        }
                      
                    } else {
                          if(this.prono == "LIS118"){
                            return (item.data ? item.data.toString().toUpperCase().indexOf(filterName.toString().toUpperCase()) > -1 : false) || (item.display ? item.display.indexOf(filterName) > -1 : false)|| (item.subjectname ? item.subjectname.indexOf(filterName) > -1 : false);
                          }
                          else{
                            return (item.data ? item.data.toString().toUpperCase().indexOf(filterName.toString().toUpperCase()) > -1 : false) || (item.display ? item.display.indexOf(filterName) > -1 : false);
                          }
                       
                    }
                });
                return rest;
            } else {
                return this.LeftSqlListOptions;
            }
        },
        rightlist(){
            if (this.RightSqlListOptions.hasOwnProperty("errcode")) return [];
            let filterName = this.txtrightQuery;
            if (filterName) {
                let rest = this.RightSqlListOptions.filter((item) => {
                    if (item.hasOwnProperty("inputcode")) {
                         if(this.prono == "LIS118"){
                            return (item.data ? item.data.toString().toUpperCase().indexOf(filterName.toString().toUpperCase()) > -1 : false) || (item.display ? item.display.indexOf(filterName) > -1 : false) || (item.inputcode ? item.inputcode.toString().toUpperCase().indexOf(filterName.toString().toUpperCase()) > -1 : false)|| (item.subjectname ? item.subjectname.indexOf(filterName) > -1 : false);
                        }
                        else{
                            return (item.data ? item.data.toString().toUpperCase().indexOf(filterName.toString().toUpperCase()) > -1 : false) || (item.display ? item.display.indexOf(filterName) > -1 : false) || (item.inputcode ? item.inputcode.toString().toUpperCase().indexOf(filterName.toString().toUpperCase()) > -1 : false);
                        }
                    } else {
                       if(this.prono == "LIS118"){
                            return (item.data ? item.data.toString().toUpperCase().indexOf(filterName.toString().toUpperCase()) > -1 : false) || (item.display ? item.display.indexOf(filterName) > -1 : false)|| (item.subjectname ? item.subjectname.indexOf(filterName) > -1 : false);
                          }
                          else{
                            return (item.data ? item.data.toString().toUpperCase().indexOf(filterName.toString().toUpperCase()) > -1 : false) || (item.display ? item.display.indexOf(filterName) > -1 : false);
                          }
                    }
                });
                return rest;
            } else {
                return this.RightSqlListOptions;
            }
        }
    },
    updated() {
        //console.log("sasa");
        if (this.param != "年龄") {
            if (this.isFirstLoad && this.datatype == "") {
                this.LeftSqlListOptions = this.leftOption;
                this.RightSqlListOptions = this.rightOption;
                this.isFirstLoad = false;
            }
            //if (this.$refs.refsearch) this.$refs.refsearch.focus();
        } else {
            if (this.$refs.ageTable)
                this.$refs.ageTable.setCurrentRow(this.ageList[0]).then(() => {
                    this.$refs.ageTable.setActiveCell(this.ageList[0], "ageyear1");
                });
        }
    },
    mounted() {
        this.radioType = this.LIS848radio;
        this.dealAgestr(this.age);
        // this.bactcountVlaue = this.bactcount;
    },
    created() {
        if (this.datatype == "") {
            this.LeftSqlListOptions = this.leftOption;
            this.RightSqlListOptions = this.rightOption;
        } else {
            this.loadAllData();
        }

        this.leftkey++;
        this.rightkey++;
    },
    watch: {
        age: {
            handler: function (val, oldVal) {
                if (val) {
                    this.dealAgestr(val);
                }
            },
            deep: true,
        },
        txtSqlListQuery: {
            handler: function (val, oldVal) {
                if (val) {
                    if (this.list.length > 0) {
                        this.$refs.PopxTableLeft.setCurrentRow(this.list[0]);
                    }
                }
            },
            deep: true,
        },
    },
    methods: {

        //取消
        SqlDialogVisibleClose() {
            this.$emit("change", "close", this.name, "");
            //this.SqlDialogVisibleSave()
        },
        //剔除
        async SqlDialogVisibleEliminate() {
            let data = await this.DataHandle();
            data.kdata = "[T]" + data.kdata;//最前面加上剔除标志
            console.log(data);
            this.$nextTick(() => {
                this.$emit("change", data.kdata, this.name, data.kdisplay);
            });
        },
        //确定
        async SqlDialogVisibleSave() {
            // let SqlTable = this.$refs.PopxTableRight.getTableData().fullData;
            // let chkdata = "";
            // if (SqlTable.length > 0) {
            //     for (let i = 0; i < SqlTable.length; i++) {
            //         chkdata += SqlTable[i].data + ",";
            //     }
            // }
            // let kdata = chkdata.substring(0, chkdata.length - 1);
            let data = await this.DataHandle();
            this.$nextTick(() => {
                this.$emit("change", data.kdata, this.name, data.kdisplay);
            });
        },
        async SqlDialogVisibleSaveLIS848() {
            let data = await this.DataHandle();
            if (data.kdata.length == 0) {
                this.radioType = -1;
            }
            this.$nextTick(() => {
                this.$emit("change", data.kdata, this.name, data.kdisplay, this.radioType);
            });
        },
        SqlDialogVisibleCloseLIS848() {
            this.$emit("change", "close", this.name, "", this.radioType);
        },
        //除外
        // async SqlDialogVisibleNotInSave() {
        //   let kdata = await this.DataHandle()
        //   if (!kdata) {
        //     this.$alert('请选择条件', '提示')
        //   } else {
        //     this.$nextTick(() => {
        //       this.$emit('change', kdata, this.name, '0')
        //     })
        //   }
        // },
        //满足
        // async SqlDialogVisibleInSave() {
        //   let kdata = await this.DataHandle()
        //   if (!kdata) {
        //     this.$alert('您没有选择条件', '提示')
        //   } else {
        //     this.$nextTick(() => {
        //       this.$emit('change', kdata, this.name, '1')
        //     })
        //   }
        // },
        async DataHandle() {
            let SqlTable = this.$refs.PopxTableRight.getTableData().fullData;
            let chkdata = "";
            let chkdisplay = "";
            if (SqlTable.length > 0) {
                for (let i = 0; i < SqlTable.length; i++) {
                    chkdata += SqlTable[i].data.toString().trim() + ","; 
                    chkdisplay += SqlTable[i].display.toString().trim() + ","; 
                }
            }
            let kdata = chkdata.substring(0, chkdata.length - 1);
            let kdisplay = chkdisplay.substring(0, chkdisplay.length - 1);
            return { kdata, kdisplay };
        },
        //sql多选
        DialogSql(sql, chkdata, name, seq) {
            this.SqlTitle = name;
            this.SitemsOptionseq = seq;
            this.loadingContain = true;
            this.$tool
                .request({
                    url: this.URL,
                    method: "post",
                    data: {
                        action: "SqlInitialList",
                        sql: sql,
                        chkdata: chkdata,
                    },
                })
                .then((res) => {
                    var collist = [
                        {
                            title: "NO.",
                            type: "index",
                            width: 50,
                        },
                    ];
                    for (let i = 0, len = res.RData.Cols.length; i < len; i++) {
                        const item = res.RData.Cols[i];
                        let colitem = {
                            field: item.field,
                            title: item.title,
                            width: item.width,
                        };
                        collist.push(colitem);
                    }
                    this.tableColumn = collist;
                    this.LeftSqlListOptions = res.LeftGrid;
                    this.RightSqlListOptions = res.RightGrid;
                    this.txtSqlListQuery = "";
                    this.SqlDialogVisible = true;
                    this.loadingContain = false;
                })
                .catch((e) => {
                    console.log("error", e);
                    this.loadingContain = false;
                });
        }, //单选,右移
        SQLSelectEvent() {
            try {
                var delrow = this.$refs.PopxTableLeft.getCurrentRow();
                if (delrow) {
                    var myrowindex = this.list.findIndex((item) => item.data == delrow.data);
                    var rowindex = this.LeftSqlListOptions.findIndex((item) => item.data == delrow.data);
                    if (this.list.length > 0) {
                        this.LeftSqlListOptions.splice(rowindex, 1);
                        if (myrowindex >= this.list.length) myrowindex = this.list.length - 1;
                        let selectrow = this.list.find((m) => m.data == this.list[myrowindex].data);
                        setTimeout(() => {
                            this.$refs.PopxTableLeft.setCurrentRow(selectrow);
                        }, 10);
                    } else {
                        this.$refs.PopxTableLeft.setCurrentRow(null);
                    }

                    this.RightSqlListOptions.push(delrow);
                    if (this.list.length > 0) {
                        if (rowindex >= this.list.length) rowindex = this.list.length - 1;
                        let selectrow = this.list[rowindex];
                        this.$refs.PopxTableLeft.setCurrentRow(selectrow);
                    } else {
                        this.$refs.PopxTableLeft.setCurrentRow(null);
                    }
                }
            } catch (e) {
                alert(e);
            }
        }, //单选，左移
        SQLNoSelectEvent() {
            try {
                var delrow = this.$refs.PopxTableRight.getCurrentRow();
                if (delrow) {
                    var alld = this.RightSqlListOptions;
                    var rowindex = alld.indexOf(delrow);
                    this.RightSqlListOptions.splice(rowindex, 1);
                    let Llen = 0;
                    if (this.LeftSqlListOptions != null) {
                        Llen = this.LeftSqlListOptions.length;
                    } else {
                        this.LeftSqlListOptions = [];
                    }
                    this.LeftSqlListOptions.splice(Llen, 0, delrow);
                    let havedata = this.RightSqlListOptions;
                    if (havedata.length > 0) {
                        if (rowindex >= havedata.length) rowindex = havedata.length - 1;
                        let selectrow = havedata[rowindex];
                        this.$refs.PopxTableRight.setCurrentRow(selectrow);
                    } else {
                        this.$refs.PopxTableRight.setCurrentRow(null);
                    }
                }
            } catch (e) {
                alert(e);
            }
        },
        SqlAllSelect() {
            //全选 右移
            let sdata = XEUtils.clone(this.list, true);
            if (sdata.length > 0) {
                sdata.forEach((delrow) => {
                    let rowindex = this.LeftSqlListOptions.findIndex((item) => item.data == delrow.data);
                    this.LeftSqlListOptions.splice(rowindex, 1);
                    //  this.$refs.PopxTableLeft.remove(delrow)
                    let Rlen = 0;
                    if (this.RightSqlListOptions != null) {
                        Rlen = this.RightSqlListOptions.length;
                    } else {
                        this.RightSqlListOptions = [];
                    }
                    this.RightSqlListOptions.splice(Rlen, 0, delrow);
                });
                this.isFirstLoad = false;
            } else {
                this.LeftSqlListOptions = [];
            }
        },
        SqlAllNoSelect() {
            //全不选 左移
            //let sdata = XEUtils.clone(this.RightSqlListOptions, true);
            let sdata = XEUtils.clone(this.rightlist, true);
            if (sdata.length > 0) {
                sdata.forEach((delrow) => {
                    let rowindex = this.RightSqlListOptions.findIndex((item) => item.data == delrow.data);
                    this.RightSqlListOptions.splice(rowindex, 1);
                    let Llen = 0;
                    if (this.LeftSqlListOptions == null) {
                        this.LeftSqlListOptions = [];
                    } else {
                        Llen = this.LeftSqlListOptions.length;
                    }
                    this.LeftSqlListOptions.splice(Llen, 0, delrow);
                });
                this.isFirstLoad = false;
             
            }
            else{
                   this.RightSqlListOptions = [];
            }
        }, 
        SqlChkExchange() {
            this.txtSqlListQuery = "";
            setTimeout(() => {
                let rdata = XEUtils.clone(this.RightSqlListOptions, true);
                let ldata = XEUtils.clone(this.LeftSqlListOptions, true);
                this.RightSqlListOptions = XEUtils.clone(ldata, true);
                this.LeftSqlListOptions = XEUtils.clone(rdata, true);
            }, 10);
        },
        //SQL多选排序
        SqlCurrSelectEvent({ rowIndex }) {
            this.sqlcurrRowIndex = rowIndex;
        },
        SqlTabledataup() {
            if (this.sqlcurrRowIndex > 0) {
                let upData = this.RightSqlListOptions[this.sqlcurrRowIndex - 1];
                let currentrow = this.RightSqlListOptions[this.sqlcurrRowIndex];
                this.RightSqlListOptions.splice(this.sqlcurrRowIndex - 1, 1);
                this.RightSqlListOptions.splice(this.sqlcurrRowIndex, 0, upData);
                this.sqlcurrRowIndex = this.sqlcurrRowIndex - 1;
                this.$nextTick(() => {
                    this.$refs.PopxTableRight.setCurrentRow(currentrow);
                });
            }
        },
        SqlTabledatadown() {
            if (this.sqlcurrRowIndex !== this.RightSqlListOptions.length - 1) {
                let downData = this.RightSqlListOptions[this.sqlcurrRowIndex + 1];
                let currentrow = this.RightSqlListOptions[this.sqlcurrRowIndex];
                this.RightSqlListOptions.splice(this.sqlcurrRowIndex + 1, 1);
                this.RightSqlListOptions.splice(this.sqlcurrRowIndex, 0, downData);
                this.sqlcurrRowIndex = this.sqlcurrRowIndex + 1;
                this.$nextTick(() => {
                    this.$refs.PopxTableRight.setCurrentRow(currentrow);
                });
            }
        },
        SqlTabledatalast() {
            if (this.sqlcurrRowIndex != this.RightSqlListOptions.length - 1) {
                let lastData = this.RightSqlListOptions[this.sqlcurrRowIndex];
                this.RightSqlListOptions.splice(this.sqlcurrRowIndex, 1);
                this.RightSqlListOptions.splice(this.RightSqlListOptions.length, 0, lastData);
                this.sqlcurrRowIndex = this.RightSqlListOptions.length - 1;
                this.$nextTick(() => {
                    this.$refs.PopxTableRight.setCurrentRow(lastData);
                });
            }
        },
        SqlTabledatafirst() {
            if (this.sqlcurrRowIndex > 0) {
                let firstData = this.RightSqlListOptions[this.sqlcurrRowIndex];
                this.RightSqlListOptions.splice(this.sqlcurrRowIndex, 1);
                this.RightSqlListOptions.splice(0, 0, firstData);
                this.sqlcurrRowIndex = 0;
                this.$nextTick(() => {
                    this.$refs.PopxTableRight.setCurrentRow(firstData);
                });
            }
        },
        async saveDataDialog() {
            let data = await this.DataHandle();
            this.$nextTick(() => {
                this.$emit("change", data.kdata, data.kdisplay);
            });
        },
        closeDataDialog() {
            this.$emit("change", "close", "");
        },
        ageEditchange(obj) {
            let o_str = obj.old; //修改前字符串
            let n_str = obj.new; //修改后字符串
            let columnName = obj.p.column.property;
            if (columnName == "ageyear1" || columnName == "ageyear2") {
                return this.$tool.onlyNumber(n_str);
            } else {
                return n_str;
            }
        },
        addAge() {
            let ageRow = {
                ageyear1: "",
                ageyear2: "",
            };
            this.$refs.ageTable.insert(ageRow).then(({ row }) => {
                this.$nextTick(() => {
                    this.$refs.ageTable.setCurrentRow(row);
                });
            });
        },
        deleteAge() {
            var delrow = this.$refs.ageTable.getCurrentRow();
            var havedata = this.$refs.ageTable.getTableData().fullData;
            console.log(delrow);
            console.log(havedata.length);
            if (delrow && havedata.length > 0) {
                var rowindex = havedata.indexOf(delrow);
                console.log(rowindex);
                this.$refs.ageTable.remove(delrow);
                if (havedata.length > 0) {
                    if (rowindex < havedata.length) rowindex = rowindex - 1;
                    let selectrow = havedata[rowindex];
                    console.log(selectrow);
                    this.$refs.ageTable.setCurrentRow(selectrow);
                }
            } else {
                this.$message({
                    message: "请先选中要删除的明细！",
                    type: "warning",
                });
            }
        },
        saveAgeDialog(type) {
            if (type == 1) {
                this.$refs.ageTable.validate((valid) => {
                    if (valid) {
                        var age = this.$refs.ageTable.getTableData().fullData;
                        let agestr = "";
                        if (age.length > 0) {
                            age.forEach((element) => {
                                agestr += element.ageyear1 + "-" + element.ageyear2 + ",";
                            });
                            agestr = agestr.slice(0, agestr.length - 1);
                        }
                        this.$emit("changeAge", "change", agestr);
                    } else {
                        this.$message.error("您有数据未填写，请填写后再保存！！");
                        return false;
                    }
                });
            } else {
                this.$emit("changeAge", "", "");
            }
        },
        dealAgestr(agestr) {
            // this.ageList = agestr;
            let ageArr = [];
            if (agestr) {
                agestr.forEach((element) => {
                    let row = element.split("-");
                    let agerow = {
                        ageyear1: row[0],
                        ageyear2: row[1],
                    };
                    ageArr.push(agerow);
                });
            }
            this.ageList = ageArr;
        },
        loadAllData() {
            let key = "RMMULTIDDL_" + this.datatype;
            if (this.rptunitid) key += "_" + this.rptunitid;
            let ccdata = null;
            let comdata = this.$ddldata.common_dataMulti;
            if (comdata) {
                let dlldataitem = comdata.find((t) => t.key == key);
                if (dlldataitem && dlldataitem.val) {
                    ccdata = dlldataitem.val;
                } else {
                    ccdata = null;
                }
            }
            // console.log("ccdata", ccdata);
            if (!ccdata) {
                this.$tool
                    .request({
                        url: "ucent/ddl",
                        method: "post",
                        data: {
                            action: "Multi_" + this.datatype,
                            prgno: this.prono,
                            rptunitid: this.rptunitid,
                        },
                    })
                    .then((res) => {
                        this.AllOption = res;
                        this.$emit("loadoption", { data: res, datatype: this.datatype });
                        this.CalcOption();
                        try {
                            // localStorage.setItem("RMCOMDDL_" + this.mydatatype + "_" + this.mykindno + "_" + this.instrid, JSON.stringify(res));
                            this.$ddldata.common_dataMulti.push({ key: key, val: res });
                        } catch (e) {}
                    })
                    .catch((e) => {
                        this.loading = false;
                        //console.log("erro", e);
                    });
            } else {
                this.AllOption = ccdata;
                this.$emit("loadoption", { data: ccdata, datatype: this.datatype });
                this.CalcOption();
            }
        },
        CalcOption() {
            this.LeftSqlListOptions = [];
            this.RightSqlListOptions = [];
            let temp = XEUtils.clone(this.AllOption, true);
            if (this.rightValue != "") {
                let k = this.rightValue.split(",");
                k.forEach((item) => {
                    let ndata = temp.find((m) => m.data == item);
                    if (ndata != undefined && ndata != null) {
                        this.RightSqlListOptions.push(ndata);
                    }
                });
                temp.forEach((item) => {
                    if (k.indexOf(item.data + "") < 0) {
                        this.LeftSqlListOptions.push(item);
                    }
                });
            } else {
                this.LeftSqlListOptions = temp;
            }
        },
        // saveBactcountDialog(type) {
        // 	if (type == 1) {
        // 		let validflag = "1";
        // 		if (!this.bactcountVlaue) validflag = "-1";
        // 		this.$emit('changeBactcount', 'change', this.bactcountVlaue, validflag);
        // 	} else {
        // 		this.$emit('changeBactcount', '', '', '');
        // 	}
        // },
        changeItemgermflag() {
            console.log(this.itemgermflag);
        },
    },
};
</script>

<style scoped>
.sqlmulpagetop {
    width: 100%;
    height: 35px;
    -webkit-box-pack: left;
    -webkit-box-align: center;
}

.sqlmulpagecenter {
    height: 400px;
    width: 100%;
    display: flex;
}

.dialog-btn {
    text-align: right;
}
/deep/ .dialog-btn .el-button {
    margin-left: 10px !important;
}
.table-deal-btn {
    text-align: center;
    margin: auto 10px;
}
.table-deal-btn div {
    margin: 5px 0;
}
.btn-exchange {
    transform: rotate(90deg);
    margin-top: 2px;
    font-size: 20px;
    height: 30px !important;
}
.btn-other {
    margin-top: 2px;
    font-size: 20px;
    height: 30px !important;
}
</style>
